var root = ui("$");
var nf = sm("do_Notification");
var do_GridView_1 = ui("do_GridView_1");
var deviceone = require("deviceone");
var communityUtil = require("helper/community");
var helperOpen = require("helper/open");
var qqHttp = require("helper/http");
var bizzType = require("helper/bizzType");
var pubUrl = require("url/pub");
//UI
var aLayoutVisitUser=ui("aLayoutVisitUser");
var messageImgsData;
//设置数据绑定的映射关系
root.setMapping({   // 此处的Mapping只能设置在 RootView 上 ;
	"aLayoutVisitUser.tag":"creatorId",
    "labelUserNick.text" : "userNick",
    "labelContent.text" : "content",
    "imageViewUserLogo.source":"userLogo",
    "labelTime.text" : "dayMinutesNewAt",
    "labelReplayCount.text" : "replyCount",
    "labelPraiseCount.text" : "praiseCount",
    "do_GridView_1.items" : "imgItems",
    "do_GridView_1.tag" : "bigImgItems",
	"do_GridView_1.visible" : "hasImg",
    "do_ImageView_5.tag" : "isPraised",
    "do_ALayout_4.tag" : "id"
});
root.on("dataRefreshed", function(){
		if(ui("do_ImageView_5").tag == 1 ){
			ui("do_ImageView_5").source = "source://image/common/praise1.png";
		}else{
			ui("do_ImageView_5").source = "source://image/common/praise.png";
		}	
})
//图片浏览注册事件
do_GridView_1.on("touch", function(data){
	helperOpen.open("source://view/reuse/imgBrowser.ui", {
		imgDatas :do_GridView_1.tag,index:data
	});
})

//访问他、她的资料
aLayoutVisitUser.on("touch", function(data){
	helperOpen.openPersonal(this.tag);
});

//点击评论按钮
ui("do_ALayout_4").on("touch", function(data, e) {
	var bizzId = ui("do_ALayout_4").tag;
	helperOpen.open("source://view/public/comment/main.ui",{"bizzId":bizzId,"bizzType":bizzType.Level2.COMMUNITY_MESSAGE});
});

//点赞按钮
ui("do_ALayout_5").on("touch", function(data, e) {
	var bizzId = ui("do_ALayout_4").tag;
	var addParams = {
            bizzId:bizzId,
            bizzType:bizzType.Level2.COMMUNITY_MESSAGE,
            communityId:communityUtil.communityVisitId()
		};
	if(ui("do_ImageView_5").tag == 1){
		//如果已点赞，再次点击则取消点赞
		qqHttp.post(pubUrl.url.praise.doCancle,addParams,function(data){
			ui("do_ImageView_5").tag = 2;
			ui("do_ImageView_5").source = "source://image/common/praise.png";
			var count = parseInt(ui("labelPraiseCount").text);
			if(count > 0){
				ui("labelPraiseCount").text = count - 1;
			}
		});
	}else{
		qqHttp.post(pubUrl.url.praise.doAdd,addParams,function(data){
			ui("do_ImageView_5").tag = 1;
			ui("do_ImageView_5").source = "source://image/common/praise1.png";
			var count = parseInt(ui("labelPraiseCount").text);
			ui("labelPraiseCount").text = count + 1;
		});
	}	
	
});